The HyperCard stack, Scripting WWW Browsers version 0.01, exemplifies how you can send AppleEvents and AppleScripts to WWW browsers. It is a rudimentary stack intended to demonstrate the points made in the section below.
The SendAppleEvent XCMD has the following syntax:
SendAppleEvent eventClass, eventID, targetProgram, replyRequest, interactionRequest, timeOutValue, data, keyword, data, keyword, data, keyword, data, keyword, data, keyword
where:
Using this command you can create a button sending an AppleEvent to MacWeb as shown below:
- eventClass
- An AEEventClass
- eventID
- An AEEventID
- targetProgram
- Path to target application in the form "zone:mac:application" if local, only "application" is required
- replyRequest
- noReply, queueReply, waitReply
- interactionRequest
- canInteract, neverInteract, alwaysInteract
- timeOutValue
- in ticks
- data
- TEXT
- keyword
- data Type (Descriptor type) If you are only sending one piece of data and it is to be the direct object, the first key is optional.
(Unfortunately, this exact example does not work with MacMosaic nor Netscape.)on mouseUp -- make sure MacWeb is open open "MacWeb" -- send the apple event necessary to to open a URL sendappleevent "wwwc", "ourl", "MacWeb", "noReply", "neverInteract","300","http://www.lib.ncsu.edu/","kURL",data2,key2,data3,key3,data4,key4,data5,key5 end mouseUp
As you can see from the example, sending AppleEvents from HyperCard to applications can be a cryptic process! This is exactly why AppleScript was invented. AppleScript is a way of putting a more-human language on top of these cryptic AppleEvents.
A developing standard AppleScript command, currently supported by MacMosiac and Netscape, is GetURL. Given a URL, this command enables you to tell your WWW browser to take the URL, retrieve the item is is associated with, and display it or save it to a file. Here is the syntax of the GetURL AppleScript command:
Consequently, a button in your HyperCard stack (or a handler in an AppleScript) containing the following code will tell MacMosic open a connection to http://www.lib.ncsu.edu/:GetURL string -- The url [to file specification] -- file the URL should be loaded into [inside reference] -- Window the URL should be loaded to [from string] -- Refererer, to be sent with the HTTP request
Similarly, this code will tell Netscape to open up a connection to http://www.lib.ncsu.edu/staff/morgan/ and save the output to a file named myfile.html on your Macintosh's desktop:tell application "MacMosaic" activate OpenURL "http://www.lib.ncsu.edu/" end tell
It should be noted that Netscape includes many more AppleScript command then just GetURL. For example, it includes a command called OpenURL which is a more full-featured version of GetURL. It also includes options to dynamically register MIME types, get the information about its open windows, and navigate back and forth between recently visited URLs.tell application "Netscape" activate set outputFile to (path to desktop as string) & "myfile.html" GetURL "http://www.lib.ncsu.edu/staff/morgan/" to file outputFile end tell
A simpler idea is to create an AppleScript with the following code:
This code simply takes the contents of the clipboard and puts it into a variable called "theURL". It then tells a WWW browser (Netscape) to open the URL. Saved as an AppleScript application that never shows its startup screen, you could save it in the Automated Tasks folder of your Apple Menu Folder. Once there you could select and copy URLs from any application (email, word processor, etc.) and open your newly created script. The script will then activate your WWW browser and open the URL.set theURL to the clipboard tell application "Netscape" activate GetURL theURL end tell
Another, more elaborate application could be the creation of a simple expert system used to search the Internet. This application would ask you questions. Based on the answers it would ask you other questions. At the end of the question and answer process, the script would dynamically create an HTML page presenting the results of the question and answer process as well as listing a number of hot links to remote Internet resources that may have the information you seek.
Eric last edited this page on September 26, 1995. Please feel free to send comments.